﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Model;
using Meraz.Core.Data;

namespace Meraz.Core.Repositories
{
    public interface IBlogRepository : IRepository<Blog, int>
    {
        List<Blog> GetByIDs(IEnumerable<int> ids);
        Blog GetByUrl(string url);
    }
    public class BlogRepository : EFRepositoryBase<Blog, int>, IBlogRepository
    {
        public BlogRepository() { }


        public override Blog GetById(int id)
        {
            return context.Blogs.Where(where1 => where1.ID == id).FirstOrDefault();
        }

        public List<Blog> GetByIDs(IEnumerable<int> ids)
        {
            return context.Blogs.Where(where1 => ids.Contains(where1.ID)).ToList();
        }

        public Blog GetByUrl(string url)
        {
            return context.Blogs.Where(where1 => where1.Url == url).FirstOrDefault();
        }

        public override void Add(Blog entity)
        {
            context.AddToBlogs(entity);
        }

        public override void Delete(Blog entity)
        {
            context.Blogs.DeleteObject(entity);
        }

        public override List<Blog> All()
        {
            return context.Blogs.ToList();
        }
    }
}
